﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SubOffice.aspx.cs" Inherits="Meeting.Web.Admin.BaseSet.SubOffice" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>分局设置</title>
    <script type="text/javascript" src="../../Scripts/jquery-1.8.2.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../../Css/main.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/cupertino/easyui.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/icon.css" />
    <script type="text/javascript" src="../../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../Scripts/locale/easyui-lang-zh_CN.js"></script>
    <!--树样式-->
    <link rel="stylesheet" href="../../Css/zTreeStyle/zTreeStyle.css" type="text/css" />
    <script type="text/javascript" src="../../Scripts/jquery.ztree.core-3.5.min.js"></script>
    <!--公用js -->
    <script type="text/javascript" src="../../Scripts/common.js"></script>
    <script type="text/javascript">
        $(function () {
            //if (request("psnID") == "") window.location = defaultUrl;
            InitGird();
        });

        function InitGird() {
            $('#mainList').datagrid({
                url: 'SubOfficeOperation.ashx?method=GetSubOffice',
                singleSelect: true,
                collapsible: false,
                  pagination: true, //是否开启分页
                pageNumber: 1, //默认索引页
                pageSize: 20,  //默认一页数据条数
                toolbar: [{
                    text: '添加',
                    iconCls: 'icon-add',
                    handler: function () {
                        AddData();
                    }
                }, '-', {
                    text: '修改',
                    iconCls: 'icon-edit',
                    handler: function () {
                        EditData();
                    }
                }, '-', {
                    text: '删除',
                    iconCls: 'icon-remove',
                    handler: function () {
                        $.messager.confirm('警告', '该记录将被永久删除，确定吗?', function (e) {
                            if (!e) return;
                            DeleteData();
                        })
                    }
                }]
            });
            //设置分页
            var p = $("#mainList").datagrid("getPager");
            $(p).pagination({
                pageSize: 20, //每页显示的记录条数，默认为10   
                pageList: [10, 20, 30], //可以设置每页记录条数的列表   
                beforePageText: '第', //页数文本框前显示的汉字   
                afterPageText: '页    共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
            });
        }


        //新增打开窗口
        function AddData() {
            $("#Id").val("0");
            $("#Number").val(1);
            $("#Name").val("");
            $("#edit").dialog("open").dialog('setTitle', '新增分局信息');
        }

        //edit
        function EditData() {
            var row = $('#mainList').datagrid('getSelected');
            if (!row) {
                $.messager.alert("提示", '请选择您要修改的记录！');
                return;
            }
            $("#Id").val(row.Id);
            $("#Number").val(row.Number);
            $("#Name").val(row.Name);
            //打开窗口
            $('#edit').window('open').dialog("setTitle", "编辑分局信息");
        }

        //保存数据
        function SaveData() {
            var id = $("#Id").val();
            var name = $("#Name").val();
            var number = $("#Number").val();
            if (number == "") {
                $.messager.alert("提示", '编号不能为空！');
                return false;
            }
            if (name == "") {
                $.messager.alert("提示", '名称不能为空！');
                return false;
            }
            var postData = { id: id, name: name, number: number };
            //提交
            $.post("SubOfficeOperation.ashx?method=Save", postData, function (data) {
                if (data.success == true) {
                    $.messager.alert("提示", '保存成功');
                    $("#mainList").datagrid('reload');
                    $("#edit").dialog("close");
                } else {
                    $.messager.alert("提示", data.Message);
                }
            });
        }

        //delete
        function DeleteData() {
            var row = $('#mainList').datagrid('getSelected');
            if (!row) {
                $.messager.alert("提示", '请选择您要删除的记录！');
                return;
            }
            var postData = { id: row.Id };
            $.post("SubOfficeOperation.ashx?method=Delete", postData, function (data) {
                if (data.success == true) {
                    $.messager.alert("提示", '删除成功');
                    $("#mainList").datagrid('reload');
                } else {
                    $.messager.alert("提示", data.Message);
                }
            });
        } 
        
    </script>
    <style type="text/css">
        .table_edit
        {
            text-align: left;
        }
        .table_edit tr
        {
            height: 32px;
        }
        input, textarea
        {
            border: 1px solid #AED0EA;
            padding: 2px;
            height: 16px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div style="min-height: 500px; width: 560px; text-align: left;">
        <table id="mainList" class="easyui-datagrid">
            <thead>
                <tr>
                    <th data-options="field:'Id',width:120,hidden:true">
                        唯一号
                    </th>
                    <th data-options="field:'Number',width:120">
                        编号
                    </th>
                    <th data-options="field:'Name',width:360">
                        名称
                    </th>
                </tr>
            </thead>
        </table>
    </div>
    <div id="edit" class="easyui-dialog" title="编辑分局信息" style="width: 400px;"  
        closed="true" buttons="#edit-buttons">
        <input id="Id" type="hidden" />
        <div title="分局信息" style="padding: 10px">
            <table class="table_edit" style="text-align: left;">
                <tr>
                    <td>
                        编号:
                    </td>
                    <td>
                        <input id="Number" name="Number" type="text" class="easyui-validatebox" data-options="required:true" />
                    </td>
                </tr>
                <tr>
                    <td>
                        名称:
                    </td>
                    <td>
                        <input id="Name" name="Name" type="text" class="easyui-validatebox" data-options="required:true" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div id="edit-buttons" style="text-align: center; padding: 5px">
        <a id="btn_add" href="#" onclick="SaveData();" class="easyui-linkbutton">提交</a>
        <a href="#" class="easyui-linkbutton" onclick="$('#edit').dialog('close');return false;">
            取消</a>
    </div>
    </form>
</body>
</html>
